{% extends '../inc/admin.content.html' %}
{% block button %}
<div class="nowrap pull-right" style="margin-top:10px">
  <button data-modal='{{'/' + ctx.controller + '/add' }}' data-title="添加用户" class='layui-btn layui-btn-small'>
      <i class='fa fa-plus'></i> 添加节点
  </button>
</div>
{% endblock %}
{% block content %}
<table class="table table-hover">
  <thead>
  <tr>
      <th style="width:20px"></th>
      <th class='text-left'>系统节点结构</th>
      <th class='text-left'></th>
      <th class='text-center nowrap'>操作</th>
  </tr>
  </thead>
  <tbody>
  {% for node in nodes %}
  <tr>
      <td style="width:20px"></td>
      <td class='text-left nowrap'>
          {{node.sql | safe}}{{node.url}}
          &nbsp;<input class='layui-input layui-input-inline title-input' name='title' data-node="{{node.node}}"
                       value="{{node.title}}" style='height:28px;line-height:28px;width:auto'/>
      </td>
      <td class='text-left nowrap'>
          <label data-tips-text="勾选后需要登录后才能访问">
            {% if node.is_login === 1 %}
              <input checked='checked' class="check-box login_{$key}"
                     type='checkbox' value='1' name='is_login' data-node="{$vo.node}"
                     onclick="!this.checked&&($('.auth_{$key}')[0].checked=!!this.checked)"/>
            {% else %}
              <input class="check-box login_{$key}" type='checkbox' value='1' name='is_login' data-node="{$vo.node}"
                     onclick="!this.checked&&($('.auth_{$key}')[0].checked=!!this.checked)"/>
            {% endif %}
              加入登录控制
          </label>
          &nbsp;&nbsp;&nbsp;&nbsp;
          <label data-tips-text="勾选后需配置用户权限后才能访问">
              {% if node.is_auth === 1 %}
              <input name='is_auth' data-node="{$vo.node}" checked='checked' class="check-box auth_{$key}"
                     type='checkbox' onclick="this.checked&&($('.login_{$key}')[0].checked=!!this.checked)"
                     value='1'/>
              {% else %}
              <input name='is_auth' data-node="{$vo.node}" class="check-box auth_{$key}" type='checkbox' value='1'
                     onclick="this.checked&&($('.login_{$key}')[0].checked=!!this.checked)"
              />
              {% endif %}
              加入权限控制
          </label>
          &nbsp;&nbsp;&nbsp;&nbsp;
          <label data-tips-text="勾选后配置菜单时节点可自动选择">
              {% if node.is_auth === 1 %}
              <input name='is_menu' data-node="{$vo.node}" checked='checked' class='check-box menu_{$key}'
                     type='checkbox' value='1'/>
              {% else %}
              <input name='is_menu' data-node="{$vo.node}" class='check-box menu_{$key}' type='checkbox' value='1'/>
              {% endif %}
              加入菜单节点选择器
          </label>
      </td>
      <td style="width: 100%;" class='text-center nowrap'>
          <span class="text-explode">|</span>
          <a  data-update="{{node.id}}" data-field='delete' data-title="确认要删除该节点吗" data-action='{{'/' + ctx.controller + '/del?id=' + vo.id }}' href="javascript:void(0)">删除节点</a>
      </td>
  </tr>
  {% endfor %}
  </tbody>
</table>
<script>
    $(function () {
        $('input.title-input').on('blur', function () {
            var data = {list: [{name: this.name, value: this.value, node: this.getAttribute('data-node')}]};
            $.form.load('asdfasf', data, 'POST', function (ret) {
                if (ret.code === 0) {
                    setTimeout(function () {
                        $.form.reload();
                    }, 3000);
                    $.msg.auto(ret);
                }
                return false;
            });
        });
        $('input.check-box').on('click', function () {
            var data = {list: []};
            $(this).parent().parent().find('input').map(function () {
                data.list.push({name: this.name, value: this.checked ? 1 : 0, node: this.getAttribute('data-node')});
            });
            $.form.load('{:url("save")}', data, 'POST', function (ret) {
                if (ret.code === 0) {
                    setTimeout(function () {
                        $.form.reload();
                    }, 3000);
                    $.msg.auto(ret);
                }
                return false;
            });
        });
    });
</script>
</table>
{% endblock %}
